﻿using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using Sustainalytics.BusinessResearchProductStates.Entities.ResearchState;

namespace Sustainalytics.Entities.ScreeningTool
{
    public static class ScreeningDataBsonDocumentExtensions
    {
        public static ResearchStates GetResearchStates(this BsonDocument bsonDocument)
            => BsonSerializer.Deserialize<ResearchStates>(bsonDocument[nameof(ScreeningData.ResearchStates)].AsBsonDocument);

        public static bool HasComprehensiveEsgResearchAvailable(this BsonDocument bsonDocument)
            => bsonDocument.GetResearchStates().ComprehensiveEsg == ResearchState.ResearchAvailable;

        public static bool HasCoreEsgResearchAvailable(this BsonDocument bsonDocument)
            => bsonDocument.GetResearchStates().CoreEsg == ResearchState.ResearchAvailable;

        public static bool HasControversyResearchAvailable(this BsonDocument bsonDocument)
            => bsonDocument.GetResearchStates().Controversy == ResearchState.ResearchAvailable;

        public static bool HasRiskRatingResearchAvailable(this BsonDocument bsonDocument)
            => bsonDocument.GetResearchStates().RiskRating == ResearchState.ResearchAvailable;
    }
}
